// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal class ModelFactoryFactory
    {
        public static IModelFactory Create(Type modelType)
        {
            IModelFactory factory;

            if (ModelHelper.IsDynamicModel(modelType))
            {
                throw new NotSupportedException("Unsupported model type.");
            }
            else
            {
                factory = new NoGenericModelFactory(modelType);
            }

            return factory;
        }

        public static IModelFactory<TModel> Create<TModel>()
        {
            IModelFactory<TModel> factory;

            if (ModelHelper.IsDynamicModel(typeof(TModel)))
            {
                throw new NotSupportedException("Unsupported model type.");
            }
            else
            {
                factory = new PocoModelFactory<TModel>(typeof(TModel));
            }

            return factory;
        }

        public static IModelFactory<DynamicModel> Create(IDictionary<string, Type> properties)
        {
            return new DynamicModelFactory(properties);
        }
    }
}
